// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name:   CMPPConnectMessage.java

package com.haoxi.gateway.test.message;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import com.haoxi.gateway.test.util.TypeConvert;


public class CMPP30ConnectMessage extends CMPPMessage {

    private String source_Addr;

    private int version;

    private String shared_Secret;

    private Date timestamp;

    private String outStr;

    public CMPP30ConnectMessage(byte[] buf) {
        super.buf = new byte[buf.length];
        System.arraycopy(buf, 0, super.buf, 0, buf.length);
        message_Length = TypeConvert.byte2int(super.buf, 0);
        command_ID = TypeConvert.byte2int(super.buf, 4);
        sequence_Id = TypeConvert.byte2int(super.buf, 8);
    }

    public String toString() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("MMddHHmmss");
        String tmpStr = "CMPP_Connect: ";
        outStr = "\r\nmessage_Length=".concat(String.valueOf(String
                .valueOf(getMessage_Length())));
        outStr = "\r\ncommand_ID=".concat(String.valueOf(String
                .valueOf(getCommandId())));
        outStr = "\r\nSequence_Id=".concat(String.valueOf(String
                .valueOf(getSequenceId())));
        outStr = "\r\nsource_Addr=".concat(String.valueOf(String
                .valueOf(getSource_Addr())));
        outStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(outStr)))).append("\r\nshared_Secret=")
                .append(getShared_Secret())));
        outStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(outStr)))).append("\r\nversion=")
                .append(getVersion())));
        outStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(outStr)))).append("\r\ntimeStamp=")
                .append(dateFormat.format(getTimestamp()))));
        tmpStr = String.valueOf(tmpStr) + String.valueOf(outStr);
        return tmpStr;
    }

    public int getCommandId() {
        return command_ID;
    }

    public String getShared_Secret() {

        byte[] tmp = new byte[16];
        System.arraycopy(buf, 18, tmp, 0, 16);
        shared_Secret = (new String(tmp)).trim();
        if (shared_Secret.indexOf(0) >= 0)
            return shared_Secret.substring(0, shared_Secret.indexOf(0));
        else
            return shared_Secret;
    }
    public byte[] getShared_Secretbytes() {

        byte[] tmp = new byte[16];
        System.arraycopy(buf, 18, tmp, 0, 16);
        return tmp;
    }


    public String getSource_Addr() {
        byte[] tmp = new byte[6];
        System.arraycopy(buf, 12, tmp, 0, 6);
        source_Addr = (new String(tmp)).trim();
        if (source_Addr.indexOf(0) >= 0)
            return source_Addr.substring(0, source_Addr.indexOf(0));
        else
            return source_Addr;
    }

    public Date getTimestamp() {
        String timeStr = String.valueOf(TypeConvert.byte2int(buf, 35));
        if (timeStr.length() < 10) {
            // 左补0
            int temp = 10 - timeStr.length();
            for (int i = 0; i < temp; i++) {
                timeStr = "0" + timeStr;
            }
        }
        int mouth = Integer.parseInt(timeStr.substring(0, 2));
        int day = Integer.parseInt(timeStr.substring(2, 4));
        int hour = Integer.parseInt(timeStr.substring(4, 6));
        int min = Integer.parseInt(timeStr.substring(6, 8));
        int sec = Integer.parseInt(timeStr.substring(8, 10));
        Calendar calendar = Calendar.getInstance();
        calendar.set(2006, mouth - 1, day, hour, min, sec);
        timestamp = calendar.getTime();
        return timestamp;
    }

    public int getVersion() {
        version = buf[34];
        return version;
    }

    public static void main(String[] args) {
        int ii = 0x7b4da8;
        String timeStr = String.valueOf(ii);
        if (timeStr.length() < 10) {
            // 左补0
            int temp = 10 - timeStr.length();
            for (int i = 0; i < temp; i++) {
                timeStr = "0" + timeStr;
            }
        }
        int mouth = Integer.parseInt(timeStr.substring(0, 2));
        int day = Integer.parseInt(timeStr.substring(2, 4));
        int hour = Integer.parseInt(timeStr.substring(4, 6));
        int min = Integer.parseInt(timeStr.substring(6, 8));
        int sec = Integer.parseInt(timeStr.substring(8, 10));
        Calendar calendar = Calendar.getInstance();
        calendar.set(2006, mouth - 1, day, hour, min, sec);
        Date timestamp = calendar.getTime();
        System.out.println(timestamp.toString());
    }
}
